<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * GMaps cache container.
 *
 * $Id: Gmap_Cache.php
 *
 * @package		Gmaps
 * @author     		Garry Welding
 * @license    		No license, just make sure you at least credit me with this somewhere.
 */
class Gmap_Cache {
	
	public function __construct()
	{
	
	}

	public function get($address)
	{
		// Get CI Instance
		$this->CI = &get_instance();
		
		$_address = trim(strtolower($address));

		$result = $this->CI->db->select('lat,lng')->from('geocode_cache')->where('LOWER(query)', $_address)->limit(1)->get();

		$resTemp = $result->result_array();
		
		if(isset($resTemp['0'])) {
			return $result->row_array();
		} else {
			return false;
		}
	}
	
	public function set($address, $lat, $lng)
	{
		// Get CI Instance
		$this->CI = &get_instance();
		
		$_address = trim(strtolower($address));
		
		$data = array(
					'query' => $_address,
					'lat' => $lat,
					'lng' => $lng
					);
		
		if($this->CI->db->insert('geocode_cache',$data)) {
			return true;
		} else {
			return false;
		}
	}

} // End Gmap Cache